package cn.itcast.nems.config;

import cn.itcast.nems.common.web.interceptor.AccountInterceptor;
import cn.itcast.nems.common.web.interceptor.TenantInfoInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AccountInterceptor accountInterceptor;
    @Autowired
    private TenantInfoInterceptor tenantInfoInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        logger.info("add interceptor");
        registry.addInterceptor(this.tenantInfoInterceptor).addPathPatterns("/**");
        registry.addInterceptor(this.accountInterceptor).addPathPatterns("/b/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }

}
